package com.utils;

public class StringUtils {

    // String转Object数组
    @SuppressWarnings("null")
    public static Object[] StringTranObject(String ids) {
	Object object[] =null;
	// 如果包含，（多选）
	if (ids.contains(",")) {
	    String idsList[] = ids.split(",");
	    object = new Object[idsList.length];
	    for (int i = 0; i < idsList.length; i++) {
		object[i] = idsList[i];
	    }
	} else {
	    object=new Object[1];
	    object[0]=ids;
	}
	return object;
    }

    // 将多选参数的id替换成占位符 例：1,2,3  替换成 ?,?,?
    public static String StringReplaceSign(String str) {
	StringBuffer newStr=new StringBuffer();
	if(str.contains(",")) {
	   String[] strings=str.split(",") ;
	   for (int i = 0; i < strings.length; i++) {
	       newStr.append("?");
	       if(i!=strings.length-1) {
		   newStr.append(",");
	       }
	   }
	   return newStr.toString();
	}else {
	    return "?";
	}
    }

    public static void main(String[] args) {
	System.out.println(StringUtils.StringTranObject("1").length);
	System.out.println(StringReplaceSign("122,2,3"));
    }

}
